package WEB.servlet.actions;

import db.dao.DoctorDao;
import db.dao.PersonDao;
import db.dto.DoctorDto;
import db.dto.PersonDto;
import db.exceptions.DoctorDaoException;
import db.factory.DoctorDaoFactory;
import db.factory.PatientDaoFactory;
import db.jdbc.PersonDaoImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * User: Vanil
 * Date: 24.12.2010
 * Time: 16:37:15
 */
public class DocRegisterAction  implements Action {
    public String perform(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try{
        String login = request.getParameter("username");
        String password = request.getParameter("password");
        String name = request.getParameter("name");
        String spec = request.getParameter("speciality");
        String exp = request.getParameter("exp");
        PersonDto perDto = new PersonDto();
        DoctorDto docDto = new DoctorDto(perDto);
        docDto .setLogin(login);
        docDto .setPassword(password);
        docDto .setName(name);
        docDto .setSpeciality(spec);
        docDto .setExp(new Integer(exp));
        docDto .setIdDepartment(1);

        DoctorDao dao = DoctorDaoFactory.create();
        dao.insert(docDto);
        return "/Login.jsp";
    } catch (DoctorDaoException e) {
        request.getSession().setAttribute("errorMessage",e.getMessage());
        return "/error.jsp";
    }

    }
}
